package com.advertisementsystem.Controller;

import com.advertisementsystem.Dto.AssignRoleDTO;
import com.advertisementsystem.Servie.UserRoleService;
import com.advertisementsystem.Exception.ResponseResult;
import com.advertisementsystem.vo.UserRoleVO;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user-role")
@Validated
public class UserRoleController {

    @Autowired
    private UserRoleService userRoleService;

    @PostMapping("/assign")
    public ResponseResult<?> assignRoles(@RequestBody @Valid AssignRoleDTO assignRoleDTO) {
        userRoleService.assignRoles(assignRoleDTO);
        return ResponseResult.success("");
    }

    @GetMapping("/{userId}")
    public ResponseResult<UserRoleVO> getUserRoles(@PathVariable Long userId) {
        return ResponseResult.success(userRoleService.getUserRoles(userId));
    }
}
